package com.webApi;

import com.ucpaas.restDemo.client.JsonReqClient;
import com.zbf.common.entity.ResponseResult;
import com.zbf.entity.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 作者: LCG
 * 日期: 2020/6/15 09:21
 * 描述: 短信服务接口类
 */

@RestController
@RequestMapping("message")
public class MessageController {

    @Autowired
    private JsonReqClient jsonReqClient;


    @Value("${message.appid}")
    private String appid;

    @Value("${message.sid}")
    private String sid;

    @Value("${message.token}")
    private String token;

    @RequestMapping("/sendMessage")
    public Object sendMessage(@RequestBody Message message){

        ResponseResult responseResult = ResponseResult.getResponseResult();
        try {
            String result=jsonReqClient.sendSms(sid, token, appid, message.getTemplateId(),message.getParam(), message.getMobile(),"");
            System.out.println("Response content is: " + result);
            responseResult.setResult(result);
            responseResult.setSuccess("ok");
            return responseResult;
        } catch (Exception e) {
            e.printStackTrace();
            responseResult.setResult("");
            responseResult.setError("error");
            return responseResult;
        }

    }

}
